@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="{{url('css/admin/jquery-ui.css')}}">
    <script type="text/javascript" src="{{url('css/admin/jquery-ui.min.js')}}"></script>
    <link href="{{url('js/lib/jquery-ui-timepicker-addon.css')}}" type="text/css" />
    <script src="{{url('js/lib/jquery-ui-timepicker-addon.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery.ui.datepicker-zh-CN.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery-ui-timepicker-zh-CN.js')}}" type="text/javascript"></script>

    <!-- 配置文件 -->
    <script type="text/javascript" src="{{url('/ueditor/ueditor.config.js')}}"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="{{url('/ueditor/ueditor.all.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')

    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">商品管理</a>
            <em>></em>
            <a href="{{route('Admin.Home.goodsIntegralList')}}">积分商品列表</a>
            <em>></em>
            <a href="={{route('Admin.Home.goodsIntegralSet')}}">积分商品设置</a>
        </div>
        @include('admin.common.goods-header')

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="goodsid" value="@if($sysGoods && $sysGoods->id){{$sysGoods->id}} @endif"/>
                <div class="gg-list">
                    <label class="tit">商品编号</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品货号" name="ssn" id="ssn" value="@if($sysGoods && $sysGoods->ssn){{$sysGoods->ssn}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入1-20个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">商品名称</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品名称" name="name" id="name" value="@if($sysGoods && $sysGoods->name){{$sysGoods->name}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入1-50个字符(一个汉字等于两个字符)</p>
                    </div>
                </div>

                {{--<div class="gg-list">
                    <label class="tit">市场价格</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入市场价格" name="m_price" id="m_price" value="@if($sysGoods && $sysGoods->m_price){{$sysGoods->m_price}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">销售价格</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入销售价格" name="s_price" id="s_price" value="@if($sysGoods && $sysGoods->s_price){{$sysGoods->s_price}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>--}}

                <div class="gg-list" data-id="ggzst2">
                    <label class="tit">商品封面图</label>
                    <div class="demo" style="display: inline-block; padding: 0; margin: 0; *display: inline; *zoom:1;">
                        <input type = "hidden" name = "pic_img" id = "pic_img2" value = "" height="70px" >
                        <div id="showimg">
                        </div>
                        <div class="btn" style="background: #00A2D4">
                            <span id="inputImage">添加图片</span>
                            <input id="img_id" type="hidden" name="thumb_id" value="@if($sysGoods && $sysGoods->thumb_id){{$sysGoods->thumb_id}} @endif">
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span >
                        </div>
                        <p class="text" id="uploadthumb">上传详情图（图片格式为jpg、png、gif，规格：高限315px,文件小于2MB）</p>
                        @if($sysGoods && $sysGoods->thumb_id != 0)<img id="img_show" style="width: 100px;padding-top: 3px;" src="{{\App\Http\Services\FileManager::getImgUrl($sysGoods->thumb_id)}}" />@endif

                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">兑换积分</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="兑换积分" name="exchange_integral" id="exchange_integral" value="@if($sysGoods && $sysGoods->exchange_integral){{$sysGoods->exchange_integral}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(注意是整数)</p>
                    </div>
                </div>


                <div class="gg-list">
                    <label class="tit">是否包邮</label>
                    <div class="cont">
                        <select name="is_free_shipping" id="is_free_shipping">
                            <option value="0" @if($sysGoods && $sysGoods->is_free_shipping == 0) selected @endif>不包邮</option>
                            <option value="1" @if($sysGoods && $sysGoods->is_free_shipping == 1) selected @endif>包邮</option>
                        </select>
                        <p class="text"></p>
                    </div>
                </div>

                <div class="gg-list" data-id="ggwz">
                    <label class="tit">商品信息：</label>
                    <div class="cont">
                        <textarea placeholder="请输入题目解析内容" name="description" id="aa"></textarea>
                    </div>
                </div>

               {{-- <div class="gg-list">
                    <label class="tit">所属分类</label>
                    <div class="cont">
                        <label class="gg-radio">
                            <select id="classify_id">
                                @if(!$sysGoods || $sysGoods->classify_id == 0 || $sysGoods->classify_id != '')
                                    <option value="0">请选择分类</option>
                                @endif
                                @foreach($classifys as $classify)
                                    <option value="{{$classify->id}}" @if($sysGoods && $sysGoods->classify_id == $classify->id)selected @endif>{{$classify->name}}</option>
                                @endforeach
                            </select>
                        </label>
                    </div>
                </div>--}}

                <div class="gg-list">
                    <label class="tit">商品状态</label>
                    <div class="cont">
                        <select name="is_shop" id="is_shop">
                            <option value="1" @if($sysGoods && $sysGoods->is_shop == 1) selected @endif>上架</option>
                            <option value="0" @if($sysGoods && $sysGoods->is_shop == 0) selected @endif>下架</option>
                        </select>
                        <p class="text">选择上架或下架 ( 默认上架 )</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">上架时间</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入上架时间" name="shop_time" id="shop_time" value="@if($sysGoods && $sysGoods->shop_time){{$sysGoods->shop_time}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>

   {{--             <div class="gg-list">
                    <label class="tit">是否推荐</label>
                    <div class="cont">
                        <select name="is_recommend" id="is_recommend">
                            <option value="0" @if($sysGoods && $sysGoods->is_recommend == 0) selected @endif>不推荐</option>
                            <option value="1" @if($sysGoods && $sysGoods->is_recommend == 1) selected @endif>推荐</option>
                        </select>
                        <p class="text">选择推荐或不推荐 ( 默认不推荐 )</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">是否热卖</label>
                    <div class="cont">
                        <select name="is_selling" id="is_selling">
                            <option value="0" @if($sysGoods && $sysGoods->is_selling == 0) selected @endif>不热卖</option>
                            <option value="1" @if($sysGoods && $sysGoods->is_selling == 1) selected @endif>热卖</option>
                        </select>
                        <p class="text">选择热卖或不热卖 ( 默认不热卖 )</p>
                    </div>
                </div>--}}

             {{--   <div class="gg-list">
                    <label class="tit">是否新品</label>
                    <div class="cont">
                        <select name="is_new" id="is_new">
                            <option value="0" @if($sysGoods && $sysGoods->is_new == 0) selected @endif>不是</option>
                            <option value="1" @if($sysGoods && $sysGoods->is_new == 1) selected @endif>是</option>
                        </select>
                        <p class="text">选择是或不是 ( 默认不是 )</p>
                    </div>
                </div>--}}

                <div class="gg-list">
                    <label class="tit">商品库存</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品库存" name="stock" id="stock" value="@if($sysGoods && $sysGoods->stock){{$sysGoods->stock}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(注意是整数)</p>
                    </div>
                </div>

      {{--          <div class="gg-list">
                    <label class="tit">积分</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入购买商品所获的积分数量" name="integral" id="integral" value="@if($sysGoods){{$sysGoods->integral}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(注意是整数)</p>
                    </div>
                </div>--}}

                <div class="gg-list">
                    <label class="tit">商品排序</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品排序" name="sort" id="sort" value="@if($sysGoods){{$sysGoods->sort}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入1-100位的数值，值越小越靠前(注意是整数)</p>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>





    <!-- content end -->
    <script>
        $(function() {

            jQuery('#shop_time').datetimepicker({
                timeFormat: "HH:mm:ss",
                dateFormat: "yy-mm-dd",
                beforeShow: function () {
                    setTimeout(
                        function () {
                            $('#ui-datepicker-div').css("z-index", 1000);
                        }, 100
                    );
                }
            });

            <!-- 实例化编辑器 -->
            var ue = UE.getEditor('aa',{
                autoHeightEnabled: true,
                initialFrameHeight:400,
                initialFrameWidth:600,
                toolbars: [
                    ['fullscreen', 'source','undo','redo','|','fontsize','horizontal','|','simpleupload','insertvideo','removeformat'],
                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
                ]
            });

            @if($sysGoods)
            ue.ready(function() {
                ue.setContent('<?php echo $sysGoods->info ?>');
            });
            @endif

            $(document).on('click', '#btn-set', function () {
                var info = "";

                ue.ready(function() {
                    info = ue.getContent();
                });

                var ssn          = $('#ssn').val();
                var name         = $('#name').val();
                var mPrice       = $('#m_price').val();
                var sPrice       = $('#s_price').val();
                var imgId        = $('#img_id').val();
                var stock        = $('#stock').val();
                var isShop       = $('#is_shop option:selected').val();
                var isRecommend  = $('#is_recommend option:selected').val();
                var isSelling    = $('#is_selling option:selected').val();
                var isNew        = $('#is_new option:selected').val();
                var isFreeShipping=$('#is_free_shipping option:selected').val();
                var sort         = $('#sort').val();
                var expressFee   = $('#express_fee').val();
                var classifyId   = $('#classify_id option:selected').val();
                var shopTime     = $('#shop_time').val();
                var integral     = $("#integral").val();
                var exchangeIntegral=$('#exchange_integral').val();
                var id           = $('#goodsid').val();

                $.ajax({
                    url: '{{route("Api.Admin.goods.setGoods")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        ssn:ssn,
                        name:name,
                        m_price:mPrice,
                        s_price:sPrice,
                        thumb_id:imgId,
                        info:info,
                        stock:stock,
                        is_shop:isShop,
                        is_recommend:isRecommend,
                        is_selling:isSelling,
                        is_new:isNew,
                        isFreeShipping:isFreeShipping,
                        sort: sort,
                        /* express_fee:expressFee,*/
                        shop_time:shopTime,
                        integral:integral,
                        classify_id:classifyId,
                        id:id,
                        exchangeIntegral:exchangeIntegral,
                        type:"integral",
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href = "{{route('Admin.Home.goodsIntegralList')}}";
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            //缩略图上传代码
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{route("Api.File.upload")}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '20mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {},

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {
                        $('#uploadthumb').html('<span style="color:red">上传中...</span>');
                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        if (responseObj.level == "success") {
                            $('#img_id').val(responseObj.data.id);
                            var imgURL = responseObj.data.img_url + "?" + Math.random();
                            $('#img_show').attr("src",imgURL);
                            $('#uploadthumb').html('<span style="color:green">上传成功</span>');
                        } else {
                            noty({type: responseObj.level, text: responseObj.message, timeout: 800});
                            $('#uploadthumb').html('<span style="color: red">上传失败，请重新上传！</span>');
                        }

                    }
                }
            });
            uploader.init();
        });
    </script>

@endsection